﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsOsgEarth
{
    public partial class Form1 : Form
    {
        [DllImport("OsgEarthWrapper.dll", EntryPoint = "InitOsgEarth", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public static extern int InitOsgEarth(IntPtr x);

        [DllImport("OsgEarthWrapper.dll", EntryPoint = "DestroyOsgEarth", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public static extern int DestroyOsgEarth();

        [DllImport("OsgEarthWrapper.dll", EntryPoint = "AddArcGISImagery", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public static extern int AddArcGISImagery();

        [DllImport("OsgEarthWrapper.dll", EntryPoint = "AddArcGISTerrainImagery", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public static extern int AddArcGISTerrainImagery();

        [DllImport("OsgEarthWrapper.dll", EntryPoint = "AddMapboxElevation", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public static extern int AddMapboxElevation();

        [DllImport("OsgEarthWrapper.dll", EntryPoint = "AddTdtImage", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public static extern int AddTdtImage();

        public Form1()
        {
            InitializeComponent();
            this.Load += Form1_Load;

            this.FormClosed += Form1_FormClosed;
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            DestroyOsgEarth();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            IntPtr ptr = this.MapPanel.Handle;
            InitOsgEarth(ptr);
            AddTdtImage();
            AddMapboxElevation();
        }
    }
}